package com.main.tripplanner.persistent;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="route")
public class Route extends PersistentEntity{
	private int id;
	private Country country;
	private Set<City> cities;
	private Set<Attraction> attractions;
	private Dosage dosage;
	private Dosage desiredDosage;
	private Float currentTime;
	private float totalTravelTime;
	private boolean toReplan; 
	
	public Route(){
		cities = new HashSet<City>();
		attractions = new HashSet<Attraction>();
		dosage = new Dosage();
		desiredDosage = new Dosage();
		currentTime = (float) 0;
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name="route_id")
	public int getId() {
		return id;
	}


	public void setId(int id) {
		this.id = id;
	}

	@ManyToOne(cascade = CascadeType.DETACH)
	@JoinColumn(name="country_id")
	public Country getCountry() {
		return country;
	}
	
	public void setCountry(Country country) {
		this.country = country;
	}
	
	@OneToMany (fetch = FetchType.LAZY, cascade=CascadeType.ALL)
	@JoinTable(name="route_cities", joinColumns = @JoinColumn(name="route_id"), inverseJoinColumns= @JoinColumn(name="city_id"))
	public Set<City> getCities() {
		return cities;
	}
	
	public void setCities(Set<City> cities) {
		this.cities = cities;
	}
	
	@OneToMany (fetch = FetchType.LAZY, cascade=CascadeType.ALL)
	@JoinTable(name="route_attractions", joinColumns = @JoinColumn(name="route_id"), inverseJoinColumns= @JoinColumn(name="attraction_id"))
	public Set<Attraction> getAttractions() {
		return attractions;
	}
	
	public void setAttractions(Set<Attraction> attractions) {
		this.attractions = attractions;
	}
	
	@Column(name="actual_time")
	public Float getCurrentTime() {
		return currentTime;
	}
	
	public void setCurrentTime(float currentTime) {
		this.currentTime = currentTime;
	}
	
	@ManyToOne(cascade = CascadeType.ALL)
	@JoinColumn(name="real_dosage_id", referencedColumnName="dosage_id")
	public Dosage getDosage() {
		return dosage;
	}
	
	public void setDosage(Dosage dosage) {
		this.dosage = dosage;
	}
	
	@ManyToOne(cascade = CascadeType.ALL)
	@JoinColumn(name="desired_dosage_id", referencedColumnName="dosage_id")
	public Dosage getDesiredDosage() {
		return desiredDosage;
	}
	
	public void setDesiredDosage(Dosage desiredDosage) {
		this.desiredDosage = desiredDosage;
	}
	
	@Column(name="total_time")
	public float getTotalTravelTime() {
		return totalTravelTime;
	}
	
	public void setTotalTravelTime(float totalTravelTime) {
		this.totalTravelTime = totalTravelTime;
	}

	@Column(name="to_replan")
	public boolean isToReplan() {
		return toReplan;
	}

	public void setToReplan(boolean toReplan) {
		this.toReplan = toReplan;
	}
	
	
	
}
